import * as types from "../types/recycleTypes";
import NetWorkUtil from "../utils/NetWorkUtil";
import ApiConstants from "../common/ApiConstants";

export function getBanners() {
  return dispatch => {
    dispatch({ type: types.RECYCLE_BANNER_INITING });
    NetWorkUtil.getWithoutLogin(ApiConstants.RECYCLE_BANNER, {})
      .then(res => {
        dispatch({ type: types.RECYCLE_BANNER_DONE, banners: res.list });
      })
      .catch(error => {
        dispatch({ type: types.RECYCLE_BANNER_ERROR, error });
      });
  };
}

export function getDeviceInfo(deviceName) {
  return dispatch => {
    dispatch({ type: types.RECYCLE_DEVICENAME_DOWN, deviceName });
    NetWorkUtil.getWithoutLogin(ApiConstants.RECYCLE_DEVICEINFO, { facility_name: deviceName })
      .then(res => {
        dispatch({ type: types.RECYCLE_DEVICEINFO_DOWN, deviceInfo: res });
      })
      .catch(error => {
        dispatch({ type: types.RECYCLE_DEVICEINFO_ERROR, error });
      });
  };
}

export function getHotRecycleDeviceList() {
  return dispatch => {
    NetWorkUtil.getWithoutLogin(ApiConstants.RECYCLE_HOTBDEVICELIST, {})
      .then(res => {
        dispatch({ type: types.RECYCLE_HOTDEVICE_DOWN, hotRecycleList: res.list });
      })
      .catch(error => {});
  };
}
